<?php
session_start();
require_once '../models/Users.php';
require_once '../models/_check_admin.php';
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Administration</title>
<?php include '../admin/_meta.php';?>
</head>
<body>

	<div id="firstLine">
		<div id="top-bar">
		<?php include '_top_bar_admin.php';?>
		</div>
	</div>
	<div id="container">
		<div id="header">
			<?php include '_menu_admin.php';?>
		</div>
		<div id="center">
			<div id="menu-left">
				<?php //include '_menu_left_admin.php';?>
			</div>
			<div id="table-user">
				<div id="table">
				<!--<div id="spdh">Sản phẩm đang hot</div>-->
				<div id="table-head">
				<div id="search">
				<a href="list_product.php">Quay lại</a>
				<input type="text"  name="key" id="key" class="txt_w300_h25" value="" placeholder="Tìm kiếm sản phẩm..."/>
				<input type="submit"  name="btn_submit_tk" value="Tìm kiếm" class="btn_w80_h29" onclick ='search();'/>
			</div>
				<?php
				if(isset($_GET['key']) and strlen($_GET['key'])>2) {
				$key = addslashes(htmlspecialchars(trim($_GET['key'])));
				$sql = "SELECT * FROM tbl_product pr, tbl_series sr,tbl_model md,tbl_brand br ,tbl_product_detail dt
						WHERE pr.brandID=br.brandID AND pr.modelID=md.modelID AND 
						pr.productID=dt.productID AND pr.seriesID=sr.seriesID AND
						CONCAT(br.brandName,md.modelName,sr.seriesName) LIKE '%$key%'
						ORDER BY br.brandName DESC";
				$rs = mysql_query($sql)or die ("show: ".mysql_error());;
						if (@mysql_num_rows($rs)>0) {
						print ('<table id="hor-zebra">
						<thread><tr>
							<th>ID</th>
							<th>Product name</th>
							<th>Quantity</th>
							<th>Price</th>
							<th>Date Add</th>
							<th>Date Modify</th>
							<th>Status</th>
							<th colspan="3">Action</th>
						</tr></thread>
						');
							while ($row = mysql_fetch_assoc($rs)) {
				print('<tbody><tr>
						<td>'.$row['productID'].'</td>
							<td>'.$row['brandName'].' '.$row['modelName'].' '.$row['seriesName'].'</td>
							<td>'.$row['quantity'].'</td>
							<td>'.number_format($row['price'],3)." VND".'</td>
							<td>'.gmdate("d/m/Y H:i A", $row['dateAdd'] + 7*3600).'</td>
							<td>'.gmdate("d/m/Y H:i A", $row['dateModify'] + 7*3600).'</td>
							<td>'.$row['status_pr'].'</td>
							<td><a href="../admin/update_product.php?productID='.$row['productID'].'">Update</a></td>
							<td><a href="../admin/update_product_dt.php?productID='.$row['productID'].'">Update Detail</a></td>
							<td><a href="../admin/del_product.php?productID='.$row['productID'].'">Delete</a></td>
							
							</tr>');}
			print('</tbody></table>');
							}else echo "<br><br><br>Không rõ kết quả ! Từ khóa nhập vào phải cách nhau khoảng trắng";
						} else {
							 echo "<br><br><br>Không rõ kết quả ! Từ khóa nhập vào phải cách nhau khoảng trắng";
						}
			?>
				</div>
			</div>
		</div>
	</div>
	<div>
		<?php include '_footer_admin.php';?>
	</div>

</body>
</html>